import { Component, OnInit, Injector } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { HttpService } from "../../core/service/http.service";
import { Router, NavigationExtras } from "@angular/router";
import {
	AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
	SystemFormControl, FieldType, ElementShowType, CustomNavigation, TeacherOutput, KeyValueOutput
} from "../..";
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import {
	FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
	FormControl
} from "@angular/forms";
import { SystemUserOutput } from '../../core/model/SystemUserDto';


@Component({
	selector: 'app-system-user',
	templateUrl: '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.html',
	styleUrls: ['../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component.scss']
})
export class SystemUserComponent extends NgZorroPageBaseComponent implements OnInit {

	constructor(injector: Injector) {
		super(injector,
			new BaseComponentConfig("SystemUser/GetAll", "SystemUser/Create", "SystemUser/Update",
				"SystemUser/Get", "SystemUser/Delete", "id", "systemuser", "系统用户管理"
			)
		);
	}


	/**
	 * 修改内容
	 * @param id 主键
	 */
	async editEntity(id: number) {
		const msgId = this.message.loading('正在获取数据', { nzDuration: 0 }).messageId;
		try {
			let url = '';
			if (this.componentConfig.PKeyFieldName && this._pKeyFieldValue) {
				url = `${this.componentConfig.GetSingle}?pid=${this._pKeyFieldValue}&id=${id}`;
			} else {
				url = `${this.componentConfig.GetSingle}?input=${id}`;
			}
			const findEntity = await this.httpService.get<SystemUserOutput>(url);
			// 关联的人员信息默认值
			const personinfo = this.arSystemFormControls.filter(e => e.fieldName === 'personId')[0];
			if (personinfo) {
				personinfo.fieldData = new Array<KeyValueOutput>(
					new KeyValueOutput(findEntity.personName, findEntity.personId),
				);
			}
			this.focusEntity = findEntity;
			this.viewType = ElementViewType.Edit;
			this.validateForm.markAsPristine();
		} finally {
			this.message.remove(msgId);
		}
	}
	getNewEntity(): SystemUserOutput {
		const user = new SystemUserOutput();
		return user;
	}

	async navigateCustom(url: string, pid: any) {

	}
	showModalForComponent(entity: any, tag: any) {
		throw new Error("Method not implemented.");
	}
}